package com.china_goldcard.igas.http.base;

import com.china_goldcard.igas.core.AppContext;
import com.china_goldcard.igas.enums.RespCode;
import com.china_goldcard.igas.exception.AppException;
import com.china_goldcard.utils.NetUtil;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Response;

/**
 * 网络是否可用对应的拦截器
 */
public final class NetAvailableInterceptor implements Interceptor{

    @Override
    public Response intercept(Chain chain) throws IOException {
        if (NetUtil.isNetworkAvailable(AppContext.getInstance())){
            return chain.proceed(chain.request());
        }else{
            throw new AppException(RespCode.NetUnAvailable.getKey(),RespCode.NetUnAvailable.getValue());
        }
    }
}
